/**
 * @param {string} s
 * @return {number}
 */
var romanToInt = function(s) {
    let rtimap = {
        'I': 1,
        'V': 5,
        'X': 10,
        'L': 50,
        'C': 100,
        'D': 500,
        'M': 1000,
    }, result = 0
    for (let index = 1; index <= s.length; index++) {
        let left = rtimap[s[index - 1]], right = ~~rtimap[s[index]]
        result += left * (left >= right ? 1 : -1)
    }
    return result
};